import axios from '@/utils/request'

import { IBlobResult, IPageResult } from './types/base'
import { IModel } from './types/models'

export function getModels(
  currentPage = 1,
  take = 10,
  params: {
    modelName: string
    fileExtension: string
  },
) {
  return axios<IPageResult<IModel>>({
    url: '/api/3d-model/list',
    method: 'get',
    params: {
      skipCount: take * (currentPage - 1),
      maxResultCount: take,
      ...params,
    },
  })
}

export function deleteModel(id: string) {
  return axios({
    url: `/api/3d-model/${id}`,
    method: 'delete',
  })
}

export function uploadModel(data: FormData) {
  return axios({
    url: `/api/3d-model/file/upload`,
    method: 'post',
    data,
  })
}

export function downloadModel(params: { modelId: string }) {
  return axios<IBlobResult>({
    url: `/api/3d-model/file/download`,
    method: 'get',
    responseType: 'blob',
    params,
  })
}
